package cn.news.biz;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.news.dao.LoginDao;
import cn.news.dao.PressDao;
import cn.news.entity.Press;
import cn.news.util.SqlSessionFactoryUtil;

public class PressBiz {
	/**
	 * 查看所有新闻
	 * @return
	 */
	public List<Press> searchAll(){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		PressDao pDao=session.getMapper(PressDao.class);
		return pDao.searchAll();
	}
	/**
	 * 增加新闻
	 * @param press
	 * @return
	 */
	public boolean addPress(Press press){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		PressDao pDao=session.getMapper(PressDao.class);
		int flag=pDao.addPress(press);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 编辑新闻
	 * @param press
	 * @return
	 */
	public boolean updatePress(Press press){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		PressDao pDao=session.getMapper(PressDao.class);
		int flag=pDao.updatePress(press);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 删除新闻
	 * @param pid
	 * @return
	 */
	public boolean delete(int pid){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		PressDao pDao=session.getMapper(PressDao.class);
		int flag=pDao.delete(pid);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 模糊查询
	 * @param keyword
	 * @return
	 */
	public String searchkeyword(String keyword){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		PressDao pDao=session.getMapper(PressDao.class);
		List<String> list=pDao.searchkeyword(keyword);
		String titles="";
		for(int i=0;i<list.size();i++){
			String title=list.get(i);
			titles +=title+",";
			
		}
		return titles.substring(0, titles.length()-1);
	}
}
